package com.shandian.multithread;

/**
 * @author shandian
 * @since 2021-11-12
 * @description 线程的顺序，直接调用 Thread.start() 方法执行不能确保线程的执行顺序
 */
public class ThreadSort02 {
    public static void main(String[] args) throws InterruptedException {

        Thread thread1=new Thread(()->{
            System.out.println("thread1");
        });
        Thread thread2=new Thread(()->{
            System.out.println("thread2");
        });
        Thread thread3=new Thread(()->{
            System.out.println("thread3");
        });

        thread1.start();
        thread1.join();

        // public final void join() throws InterruptedException {
        //        join(0);
        //    }

        //public final synchronized void join(long millis)
        //    throws InterruptedException {
        //        long base = System.currentTimeMillis();
        //        long now = 0;
        //
        //        if (millis < 0) {
        //            throw new IllegalArgumentException("timeout value is negative");
        //        }
        //
        //        if (millis == 0) {
        //            while (isAlive()) {
        //                wait(0);
        //            }
        //        } else {
        //            while (isAlive()) {
        //                long delay = millis - now;
        //                if (delay <= 0) {
        //                    break;
        //                }
        //                wait(delay);
        //                now = System.currentTimeMillis() - base;
        //            }
        //        }
        //    }



        thread2.start();
        thread2.join();
        thread3.start();
        thread3.join();

    }
}
